//    Copyright (C) Kherty.  All rights reserved.
using OpenLS.Core.Serialization;
using OpenLS.Spreadsheet.Office2003;

namespace OpenLS.Spreadsheet
{
    partial class ColumnCollection: IOffice2003XmlSerializable
    {
        #region IXmlSpreadsheetSerializable Members

        void IOffice2003XmlSerializable.ReadXmlSpreadsheet(ReadContext context)
        {
            int availableIndex = 0;
            while (context.ReaderLocalName == "Column")
            {
                using (ReadContext c = context.Read("Column"))
                {
                    int realIndex = c.GetOptionalInteger(c.Namespace + "Index", availableIndex+1)-1;
                    Column column = new Column(Worksheet, realIndex);
                    Add(column);
                    string styleId = c.GetOptionalString( c.Namespace + "StyleID");
                    if (styleId != null)
                        column.SetFormattingRecord(c.GetData<StyleLookup>()[styleId]);
                    //\\hidden;
                    double? width = c.GetOptionalDouble(c.Namespace + "Width");
                    if (width != null)
                        column.Width = PointsToPixelConverter.ToPixel(width.Value);
                    //\\Span, Caption, AutoFitWidth
                    availableIndex = column.Index + 1;

                }
            }
        }

        #endregion
    }
}
